<template>
  <div class="container">
    <a-space direction="vertical" :fill="true" :size="16" class="space">
      <a-row
        class="grid-demo"
        :gutter="24"
        justify="space-between"
        align="center"
      >
        <a-col :span="12">
          <div class="title"> 实时信息：{{ route.params.name }} </div>
        </a-col>
        <a-col :span="12">
          <div style="float: right">
            <a-button type="text" @click="back">返回</a-button>
          </div>
        </a-col>
      </a-row>
      <a-row class="grid-demo" :gutter="24" justify="space-between">
        <a-col flex="224px">
          <div class="data-grid">
            <div class="title">心率</div>
            <div class="number">
              {{ userData.heartrate }}
              <span>次/每分</span>
            </div>
          </div>
        </a-col>
        <a-col flex="224px">
          <div class="data-grid">
            <div class="title">血氧</div>
            <div class="number">
              {{ userData.bloodoxygen }}
              <span>mmol/L</span>
            </div>
          </div>
        </a-col>
        <a-col flex="224px">
          <div class="data-grid">
            <div class="title">舒张压</div>
            <div class="number">
              {{ userData.dbp }}
              <span>次/每分</span>
            </div>
          </div>
        </a-col>
        <a-col flex="224px">
          <div class="data-grid">
            <div class="title">BMI</div>
            <div class="number">
              {{ userData.userBMI }}
              <span>Kg/m²</span>
            </div>
          </div>
        </a-col>
        <a-col flex="224px">
          <div class="data-grid">
            <div class="title">睡眠</div>
            <div class="number">
              {{ userData.userSleep }}
              <span>h</span>
            </div>
          </div>
        </a-col>
      </a-row>
      <a-row class="grid-demo" :gutter="24">
        <a-col :span="24">
          <data-histogram
            :id="route.params.id"
            :name="route.params.name"
          ></data-histogram>
        </a-col>
      </a-row>
      <a-row class="grid-demo" :gutter="24">
        <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12" :xxl="12">
          <heart-rate
            :id="route.params.id"
            :name="route.params.name"
          ></heart-rate>
        </a-col>
        <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12" :xxl="12">
          <blood-sugar
            :id="route.params.id"
            :name="route.params.name"
          ></blood-sugar>
        </a-col>
      </a-row>
    </a-space>
  </div>
</template>

<script lang="ts" setup>
  import { ref } from 'vue';
  import { Message } from '@arco-design/web-vue';
  import { useRoute, useRouter } from 'vue-router';
  import { queryRealTimeHealthy } from '@/api/dashboard';

  import dataHistogram from './components/data-histogram.vue';
  import heartRate from './components/heart-rate.vue';
  import bloodSugar from './components/blood-sugar.vue';

  const userData: any = ref({
    userSleep: 0,
    userBMI: 0,
    heartrate: 0,
    bloodoxygen: 0,
    dbp: 0,
  });
  const router = useRouter();
  const route = useRoute();

  const back = () => {
    router.back();
  };

  const initData = async () => {
    const { code, data, msg } = await queryRealTimeHealthy({
      userId: route.params.id,
    });
    if (code !== 200) {
      Message.error(msg);
      return;
    }
    // eslint-disable-next-line prefer-destructuring
    userData.value = data[0];
  };
  initData();
</script>

<style lang="less" scoped>
  .container {
    padding-bottom: 0;
    display: flex;
    background-color: var(--color-bg-2);
    padding: 24px;
    .space {
      width: 100%;
    }
    .grid-demo {
      width: 100%;
      .data-grid {
        width: 224px;
        height: 134px;
        border-radius: 8px;
        padding: 24px;
        border: 1px dashed var(--color-text-2);
        margin-bottom: 24px;
        .title {
          font-size: 16px;
          font-weight: 400;
          color: var(--color-text-2);
          line-height: 19px;
        }
        .number {
          font-size: 32px;
          font-weight: 600;
          color: var(--color-text-2);
          line-height: 48px;
          margin-top: 16px;
          span {
            font-size: 16px;
            font-weight: 400;
            color: var(--color-text-5);
            line-height: 19px;
          }
        }
      }
    }
    .title {
      font-size: 14px;
      font-weight: 500;
      color: var(--color-text-2);
      line-height: 16px;
    }
  }
</style>

<style lang="less" scoped>
  // responsive
  .mobile {
    .container {
      display: block;
      background-color: var(--color-bg-2);
    }
    .right-side {
      // display: none;
      width: 100%;
      margin-left: 0;
      margin-top: 16px;
    }
  }
</style>
